weiXinController.controller('kgyOrderPageCtl', ['$scope', '$state', '$stateParams', '$timeout', '$interval', '$compile',
    '$rootScope', function ($scope, $state, $stateParams, $timeout, $interval, $compile, $rootScope) {
        let mBottomScrollTop;
        let mBindSldModalScrollTop;
        //1.打开窗口 2.记录位置 3.停止滚动事件
        $scope.miOpen = function (id) {
            $('#' + id).modal('show');
            return;
            if (id == "selectUserModal") {
                $('#' + id).modal('show');
                return
            }
            $('#' + id).modal('show');
            mBottomScrollTop = document.scrollingElement.scrollTop;
            mBindSldModalScrollTop = document.scrollingElement.scrollTop;
            EdeyeAdmin.stopScroll(mBottomScrollTop);//禁止滚动，停止在某个位置
        };
        //1.关闭窗口 2.回滚到之前的位置 3.放开滚动
        $scope.miClose = function (id) {
        	$('#' + id).modal('hide');
        	return;
            //关闭绑定备件窗口之外的窗口
            if ($("#selectBindSldModal").is(":visible") && id != "selectBindSldModal") {
                $("#viewStoreModal").hide();
                return
            } else {
                $('#' + id).modal('hide');
            }
            if ($("#storeSettingShow").is(":visible") && "selectUserModal" == id) {
                $('#' + id).modal('hide');
                return
            }
            $('#' + id).modal('hide');
            EdeyeAdmin.openScroll(mBottomScrollTop);//打开滚动，回到某个位置
        };

        // 入库单查看（查看申领单）
        $scope.storeView = function (id, status) {
            $scope.orderRecordViewList = [];
            $scope.bind_record = {};
            EdeyeAdmin.post({
                url: '/orderInfo/getOrderBalanceRecordById',
                data: {
                    id: id,
                    status: status
                }
            }, {
                SUCCESS: function (ret) {
                    var orderInfoRecord = ret.data;

                    $scope.warehouse_info_id = ret.order.warehouse_info_id;

                    for (var tmpKey in orderInfoRecord) {
                        var shelf_show_info = '';
                        var weight_show_info = '';
                        var rfid_show_info = '';
                        var qr_show_info = '';
                        if (ret.order.type === 'BALANCE') {
                            if (orderInfoRecord[tmpKey].type === 'RFID') {
                                var orderInfoRecordRfids = JSON.parse(orderInfoRecord[tmpKey].rfid);
                                for (var tmpInnerKey in orderInfoRecordRfids) {
                                    if (tmpInnerKey === '0') {
                                        rfid_show_info = orderInfoRecordRfids[tmpInnerKey].name;
                                    } else {
                                        rfid_show_info += ' | ' + orderInfoRecordRfids[tmpInnerKey].name;
                                    }
                                }
                            } else if (orderInfoRecord[tmpKey].type === 'QR') {
                                // var orderInfoRecordQrs = JSON.parse(orderInfoRecord[tmpKey].qr);
                                // for(var tmpInnerKey in orderInfoRecordQrs){
                                //     if(tmpInnerKey === '0'){
                                //          qr_show_info = orderInfoRecordQrs[tmpInnerKey].id;
                                //     }else{
                                //         qr_show_info += ' | ' + orderInfoRecordQrs[tmpInnerKey].id;
                                //     }
                                //  }
                                // 19-02-19 16:27:00 改成如下
                                var orderInfoRecordQrs = JSON.parse(orderInfoRecord[tmpKey].materiel_info);
                                for (var tmpInnerKey in orderInfoRecordQrs) {
                                    if (tmpInnerKey === '0') {
                                        qr_show_info = orderInfoRecordQrs[tmpInnerKey];
                                    } else {
                                        qr_show_info += ' | ' + orderInfoRecordQrs[tmpInnerKey];
                                    }
                                }
                            } else if (orderInfoRecord[tmpKey].type === 'WEIGHT') {
                                shelf_show_info = orderInfoRecord[tmpKey].shelf_parent.name + ' - ' + orderInfoRecord[tmpKey].shelf.name;
                                weight_show_info = orderInfoRecord[tmpKey].basket_parent.name + ' - ' + orderInfoRecord[tmpKey].basket.name
                            }
                        }
                        $scope.orderRecordViewList.push({
                            order_type: ret.order.type,
                            name: orderInfoRecord[tmpKey].name,
                            sp_code: orderInfoRecord[tmpKey].sp_code,
                            batch_code: orderInfoRecord[tmpKey].batch_code,
                            type: orderInfoRecord[tmpKey].type,
                            num: orderInfoRecord[tmpKey].num,
                            gmt_user: orderInfoRecord[tmpKey].gmt_user,
                            shelf_show_info: shelf_show_info,
                            weight_show_info: weight_show_info,
                            rfid_show_info: rfid_show_info,
                            qr_show_info: qr_show_info
                        });
                        $scope.bind_record = ret.bind_record;
                    }
                    $scope.$apply();
                    //展示在别的窗口上面
                    if ($("#selectBindSldModal").is(":visible")) {
                        $("#viewStoreModal").show()
                    } else {
                        $scope.miOpen("viewStoreModal");
                    }
                }
            });
        }
        //绑定申领单
        $scope.callBackSelectBindSldModal = function (data) {
            // TODO 二次确认 注释 4月8日
            // layer.confirm('是否绑定此申领单?', {
            //     btn: ['确认', '取消'],
            //     closeBtn: false
            // }, function () {
                EdeyeAdmin.post({
                    url: '/orderInfo/bindOrder',
                    data: {tb_order_id: $scope.tb_order_id, tb_order_bid: $scope.tb_order_bid, order_id: data.id}
                }, {
                    SUCCESS: function (ret) {
                        if (ret.code == 200) {
                            $scope.search();
                            layer.closeAll();
                            // $scope.miClose('selectBindSldModal');
                            $('#selectBindSldModal').modal('hide');
                        }
                        EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    }
                });
            // });
        };

        // 备件搜索条件
        $scope.orderSearchObj = {
            type_account: '',
            type: '',
            type_from: '',
            status: '',
            claimant_type: 'SELF'
        }

        $scope.loginInfo = EdeyeAdmin.getLoginInfo().loginInfo;

        // 分页初始化条件
        var param = {
            id: 'tableDemo',
            checkbox: false,
            column: [
                {
                    type: 'rowNum',
                    title: '编号',
                    titleTdStyle: 'width: 100px;color: #17a2b8;'
                }, {
                    type: 'key',
                    mapping: 'id',
                    show: false
                }, {
                    mapping: 'show_name',
                    title: '申领人',
                    trans: function (data) {
                        if (data.type === 'BALANCE') {
                            return '自己';
                        }
                        if (data.applicant_user_id == 0) {
                            return '待设置';
                        }
                        if (data.applicant_user_id != 0) {
                            return data.show_name;
                        }
                    }
                }, {
                    type: '?',
                    title: '账内/账外',
                    trans: function (data) {
                        if (data.type_account === 'OUT') {
                            return '账外';
                        }
                        if (data.type_account === 'IN') {
                            return '账内';
                        }
                    }
                }, {
                    type: '?',
                    title: '类型',
                    trans: function (data) {
                        if (data.type === 'OUT') {
                            return '出库';
                        }
                        if (data.type === 'BALANCE') {
                            return '冲销';
                        }
                        if (data.type === 'BORROW') {
                            return '借出';
                        }
                        if (!data.type) {
                            return '待设置';
                        }
                    }
                }, {
                    type: '?',
                    title: '自建/同步',
                    trans: function (data) {
                        if (data.type_from === 'IN') {
                            return '自建';
                        }
                        if (data.type_from === 'OUT_COMMON' || data.type_from === 'OUT_CANCEL') {
                            return '同步';
                        }
                    }
                }, {
                    mapping:'approval_type',
                    title:'审批方式',
                    trans:function(data){
                        if(data.approval_type === 'COMMON'){
                            return '正常';
                        }
                        if(data.approval_type === 'URGENT'){
                            return '紧急';
                        }
                        if(!data.approval_type){
                            return '无';
                        }
                    }
                },{
                    type: '?',
                    title: '状态',
                    trans: function (data) {
                        if (data.status === 'INIT') {
                            return '未完成';
                        }
                        if (data.status === 'UNBACK') {
                            return '待归还';
                        }
                        if (data.status === 'DOING') {
                            return '处理中';
                        }
                        if (data.status === 'DONE') {
                            return '已完成';
                        }
                        if (data.status === 'BINDED') {
                            return '已绑定';
                        }
                        if (data.status === 'BALANCED') {
                            return '已冲销';
                        }
                        if (data.status === 'CANCEL') {
                            return '已取消';
                        }
                    }
                }, {
                    mapping: '?',
                    title: '操作时间',
                    trans: function (data) {
                        return data.gmt_modified;
                    }
                }, {
                    type: 'function',
                    title: '操作',
                    titleDivStyle: 'text-align: center',
                    dataDivStyle: 'text-align: center',
                    func: [{
                        title: '冲销',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-balance-scale"></i>',
                        text: '冲销',
                        show: function (data) {
                            // 只有冲销类型+状态为初始化的才能冲销
                            return (data.type === 'BALANCE' && data.status === 'INIT');
                        },
                        func: function (data) {
                            $scope.storeBalance(data.id);
                        }
                    }, {
                        title: '修改',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-pencil-alt"></i>',
                        text: '修改',
                        show: function (data) {
                            // 只有冲销类型+状态为初始化的才能冲销
                            return (data.type === 'BALANCE' && data.status === 'INIT');
                        },
                        func: function (data) {
                            $scope.updateBalance(data.id);
                        }
                    }, {
                        title: '查看',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-eye"></i>',
                        text: '查看',
                        func: function (data) {
                            $scope.storeView(data.id, data.status);
                        }
                    }, {
                        title: '取消',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-ban"></i>',
                        text: '取消',
                        show: function (data) {
                            // 只有自建+状态为初始化的才能取消
                            return (data.status === 'INIT' && data.type_from === 'IN' && data.gmt_user === $scope.loginInfo.id);
                        },
                        func: function (data) {
                            $scope.storeCancel(data.id);
                        }
                    }, {
                        title: '归还',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-clipboard"></i>',
                        text: '归还',
                        show: function (data) {
                            return (data.status === 'UNBACK');
                        },
                        func: function (data) {
                            $scope.showGiveBackModel(data);
                        }
                    }, {
                        title: '设置申领人',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-address-book"></i>',
                        text: '设置申领人',
                        show: function (data) {
                            // 只有同步过来的+状态为初始化的才能绑定
                            return (data.applicant_user_id == 0 && (data.type_from === 'OUT_COMMON' || data.type_from === 'OUT_CANCEL') && data.status === 'INIT');
                        },
                        func: function (data) {
                            $scope.storeSetting(data);
                        }
                    }, {
                        title: '绑定',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-bullseye"></i>',
                        text: '绑定',
                        show: function (data) {
                            // 只有同步过来的+状态为初始化的才能绑定
                            return ((data.type_from === 'OUT_COMMON' || data.type_from === 'OUT_CANCEL') && data.status === 'INIT');
                        },
                        func: function (data) {
                            $scope.openSelectBindSldModal(data);
                        }
                    }]
                }
            ],
            pageConfig: {
                showGoNum: false
            },
            page: function (cmd, currentPage, pageSize, totalPageNum) {
                if ('first' === cmd) {
                    currentPage = 1;
                } else if ('prev' === cmd) {
                    currentPage--;
                } else if ('next' === cmd) {
                    currentPage++;
                } else if ('last' === cmd) {
                    currentPage = totalPageNum;
                } else if ('change' === cmd) {
                    currentPage = 1;
                }

                $scope.search(currentPage, pageSize);
            }
        };
        EdeyeAdmin.initDataTablePhone(param, {data: []});

        // 冲销申领单
        $scope.storeBalance = function (id) {
            // TODO 二次确认 注释 4月8日
            // layer.confirm('是否冲销该申领单?', {
            //     btn: ['确认', '取消'],
            //     closeBtn: false
            // }, function () {
                EdeyeAdmin.post({
                    url: '/orderInfo/orderBalance',
                    data: {id: id}
                }, {
                    SUCCESS: function (ret) {
                        $scope.search();
                        EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    }
                });
                layer.closeAll();
            // });
        }

        // 入库单取消
        $scope.storeCancel = function (id) {
            // TODO 二次确认 注释 4月8日
            // layer.confirm('是否取消该申领单?', {
            //     btn: ['确认', '取消'],
            //     closeBtn: false
            // }, function () {
                EdeyeAdmin.post({
                    url: '/orderInfo/orderCancel',
                    data: {id: id}
                }, {
                    SUCCESS: function (ret) {
                        $scope.search();
                        EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    }
                });
                layer.closeAll();
            // });
        }

        // 查询入库单信息
        $scope.search = function (currentPage, pageSize) {
            $scope.orderSearchObj.currentPage = (currentPage === undefined ? 1 : currentPage);
            $scope.orderSearchObj.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(param.id) : pageSize);
            $scope.orderSearchObj.claimant_type = $('#claimant_type').val().toString();
            EdeyeAdmin.post({
                url: '/orderInfo/page',
                data: $scope.orderSearchObj,
            }, {
                SUCCESS: function (ret) {
                    if (ret.code === '200') {
                        EdeyeAdmin.setDataTableDataPhone(param, ret.data);
                    }
                }
            });
        }

        $scope.updateBalance = function (id) {
            $state.go('/kgy/order/edit', {param: EdeyeAdmin.zip({'id': id})});
        }

        $scope.search();

        $scope.orderRecordViewList = [];


        $scope.hide = function () {
            $('#viewStoreModal').modal('hide');
            EdeyeAdmin.openScroll(mBottomScrollTop);
        }


        //########################## 绑定申领单 START ##########################
        // 绑定申领单分页初始化条件
        var bindSldParam = {
            id: 'bindSldTable',
            checkbox: false,
            column: [
                {
                    type: 'rowNum',
                    title: '编号',
                }, {
                    type: 'key',
                    mapping: 'id',
                    show: false
                }, {
                    mapping: 'show_name',
                    title: '申领人',
                    trans: function (data) {
                        if (data.type === 'BALANCE') {
                            return '自己';
                        }
                        if (data.applicant_user_id == 0) {
                            return '待设置';
                        }
                        if (data.applicant_user_id != 0) {
                            return data.show_name;
                        }
                    }
                }, {
                    mapping: 'type_account',
                    title: '账内/账外',
                    trans: function (data) {
                        if (data.type_account === 'OUT') {
                            return '账外';
                        }
                        if (data.type_account === 'IN') {
                            return '账内';
                        }
                    }
                }, {
                    mapping: 'type',
                    title: '类型',
                    trans: function (data) {
                        if (data.type === 'OUT') {
                            return '出库';
                        }
                        if (data.type === 'BALANCE') {
                            return '冲销';
                        }
                        if (data.type === 'BORROW') {
                            return '借出';
                        }
                        if (!data.type) {
                            return '待设置';
                        }
                    }
                }, {
                    mapping: 'type_from',
                    title: '自建/同步',
                    trans: function (data) {
                        if (data.type_from === 'IN') {
                            return '自建';
                        }
                        if (data.type_from === 'OUT_COMMON') {
                            return '同步';
                        }
                    }
                }, {
                    mapping: 'status',
                    title: '状态',
                    trans: function (data) {
                        if (data.status === 'INIT') {
                            return '未完成';
                        }
                        if (data.status === 'UNBACK') {
                            return '待归还';
                        }
                        if (data.status === 'DOING') {
                            return '处理中';
                        }
                        if (data.status === 'DONE') {
                            return '已完成';
                        }
                        if (data.status === 'BINDED') {
                            return '已绑定';
                        }
                        if (data.status === 'BALANCED') {
                            return '已冲销';
                        }
                        if (data.status === 'CANCEL') {
                            return '已取消';
                        }
                    }
                }, {
                    mapping: 'gmt_modified',
                    title: '操作时间'
                }, {
                    type: 'function',
                    title: '操作',
                    titleDivStyle: 'text-align: center',
                    dataDivStyle: 'text-align: center',
                    func: [{
                        title: '查看',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-eye"></i>',
                        text: '查看',
                        func: function (data) {
                            $scope.storeView(data.id, data.status);
                        }
                    }, {
                        title: '选择',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-check"></i>',
                        text: '选择',
                        func: function (data) {
                            $scope.callBackSelectBindSldModal(data);
                        }
                    }]
                }
            ],
            pageSize: [[5], 10, 50, 100, 1000],
            page: function (cmd, currentPage, pageSize, totalPageNum) {
                if ('first' === cmd) {
                    currentPage = 1;
                } else if ('prev' === cmd) {
                    currentPage--;
                } else if ('next' === cmd) {
                    currentPage++;
                } else if ('last' === cmd) {
                    currentPage = totalPageNum;
                } else if ('change' === cmd) {
                    currentPage = 1;
                }
                $scope.bindSldPageSearch(currentPage, pageSize);
            }
        };
        EdeyeAdmin.initDataTablePhone(bindSldParam, {data: []});

        $scope.bindSldPageSearch = function (currentPage, pageSize) {
            var postData = {}
            postData.currentPage = (currentPage === undefined ? 1 : currentPage);
            postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(bindSldParam.id) : pageSize);
            EdeyeAdmin.post({
                url: '/orderInfo/getBindSldPage',
                data: postData
            }, {
                SUCCESS: function (ret) {
                    if (ret.code === '200') {
                        EdeyeAdmin.setDataTableDataPhone(bindSldParam, ret.data);
                        $scope.miOpen('selectBindSldModal')
                    }
                }
            });
        }

        $scope.openSelectBindSldModal = function (data) {
            $scope.tb_order_id = data.id;
            $scope.tb_order_bid = data.bid;
            $scope.bindSldPageSearch();

        }


        //########################## 绑定申领单 END ##########################

        //########################## 申领单归还 START ##########################
        //归还
        $scope.showGiveBackModel = function (data) {
            $scope.order = data;
            EdeyeAdmin.post({
                url: '/orderInfo/getGiveBackData',
                data: {id: data.id, type_account: data.type_account}
            }, {
                SUCCESS: function (ret) {
                    $scope.giveBackRecordViewList = ret.data;
                    $scope.$apply();
                    console.log(ret);
                }
            });
            // $scope.miOpen("giveBackModel");
            $('#giveBackModel').modal('show');
        }

        $scope.bind_rfid = [];

        // RFID分页初始化条件
        var rfidPageParam = {
            id: 'rfidTable',
            checkbox: false,
            column: [
                {
                    type: 'rowNum',
                    title: '编号',
                }, {
                    type: 'key',
                    mapping: 'id',
                    show: false
                }, {
                    mapping: 'name',
                    title: 'RFID名称'
                }, {
                    mapping: 'code',
                    title: 'RFID编码'
                }, {
                    mapping: 'gmt_modified',
                    title: 'RFID最后操作时间'
                }, {
                    type: 'function',
                    title: '操作',
                    titleDivStyle: 'text-align: center',
                    dataDivStyle: 'text-align: center',
                    func: [{
                        title: '选择',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-check"></i>',
                        text: '选择',
                        func: function (data) {
                            $scope.callBackSelectRfidModal(data);
                        }
                    }]
                }
            ],
            pageSize: [[5], 10, 50, 100, 1000],
            page: function (cmd, currentPage, pageSize, totalPageNum) {
                if ('first' === cmd) {
                    currentPage = 1;
                } else if ('prev' === cmd) {
                    currentPage--;
                } else if ('next' === cmd) {
                    currentPage++;
                } else if ('last' === cmd) {
                    currentPage = totalPageNum;
                } else if ('change' === cmd) {
                    currentPage = 1;
                }
                $scope.rfidPageSearch(currentPage, pageSize);
            }
        };
        EdeyeAdmin.initDataTablePhone(rfidPageParam, {data: []});
        
        $scope.rfidSearchObj = {
        	name:'',
        	code:''
        }

        $scope.rfidPageSearch = function (currentPage, pageSize) {
            var postData = {status: 'UNBIND'}
            postData.currentPage = (currentPage === undefined ? 1 : currentPage);
            postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(rfidPageParam.id) : pageSize);
            postData.name = $scope.rfidSearchObj.name;
            postData.code = $scope.rfidSearchObj.code;
            EdeyeAdmin.post({
                url: '/orderInfo/getAllRfidByType',
                data: postData
            }, {
                SUCCESS: function (ret) {
                    if (ret.code === '200') {
                        $scope.prefix = ret.prefix;
                        EdeyeAdmin.setDataTableDataPhone(rfidPageParam, ret.data);
                        // $scope.miOpen("selectRfidModal");
                        $('#giveBackModel').modal('hide');
                        $('#selectRfidModal').modal('show');
                        setTimeout(function(){
                        	$('body').addClass('modal-open');
                        },1000);
                    }
                }
            });
        }
        
        $scope.closeSelectRfidModal = function(){
        	$('#selectRfidModal').modal('hide');
        	$('#giveBackModel').modal('show');
            setTimeout(function(){
            	$('body').addClass('modal-open');
            },1000);
        }

        // 弹出选择rfid标签的modal
        $scope.openSelectRfidModal = function (data) {
            $scope.tempRecord = data;
            $scope.rfidPageSearch();
        }

        // 选择rfid标签后回调的方法
        $scope.callBackSelectRfidModal = function (data) {
            $scope.tempRecord.rfid_name = data.name;
            $scope.tempRecord.rfid_id = data.id
            $scope.$apply();
            // $scope.miClose("selectRfidModal")
        	$scope.closeSelectRfidModal();
        }


        //提交归还
        $scope.submitGiveBack = function () {
            $scope.transData = [];
            $scope.rfid_ids = [];
            for (let index in $scope.giveBackRecordViewList) {
                var temp = $scope.giveBackRecordViewList[index];

                if (temp.type == 'RFID' && !temp.rfid_id) {
                    EdeyeAdmin.closeMsg("归还RFID类型备件，必须绑定RFID标签", true, 1);
                    return;
                }

                if (temp.rfid_id) {
                    $scope.rfid_ids[index] = temp.rfid_id;
                }
                $scope.transData[index] = {
                    batch_code: temp.batch_code,
                    sp_code: temp.sp_code,
                    materiel_info_id: temp.materiel_info_id,
                    rfid_id: temp.rfid_id,
                    type: temp.type,
                    type_account: $scope.order.type_account,
                }
            }
            ;

            if ((new Set($scope.rfid_ids)).size != $scope.rfid_ids.length) {
                EdeyeAdmin.closeMsg("存在重复RFID标签", true, 1);
                return;
            }

            console.info($scope.transData);

            EdeyeAdmin.post({
                url: '/orderInfo/giveBack',
                data: {order_id: $scope.order.id, param: JSON.stringify($scope.transData)}
            }, {
                SUCCESS: function (ret) {
                    EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    // $scope.miClose("giveBackModel");
                    $('#giveBackModel').modal('hide');
                    $scope.search();
                }
            });
            layer.closeAll();
        }
        //########################## 申领单归还 END ##########################

        //########################## 设置同步申领单审批人 START ##########################

        // 同步申领单设置
        // 批次号分页初始化条件
        var userPageParam = {
            id: 'userTable',
            checkbox: false,
            column: [
                {
                    type: 'rowNum',
                    title: '编号',
                }, {
                    type: 'key',
                    mapping: 'id',
                    show: false
                }, {
                    mapping: 'show_name',
                    title: '用户名'
                }, {
                    mapping: 'login_name',
                    title: '工号'
                }, {
                    mapping: 'gmt_create',
                    title: '录入时间'
                }, {
                    type: 'function',
                    title: '操作',
                    titleDivStyle: 'text-align: center',
                    dataDivStyle: 'text-align: center',
                    func: [{
                        title: '选择',
                        css: 'btn-sm btn-outline-info',
                        text111: '<i class="fas fa-check"></i>',
                        text: '选择',
                        func: function (data) {
                            $scope.callBackSelectUserModal(data);
                        }
                    }]
                }
            ],
            pageSize: [[5], 10, 50, 100],
            page: function (cmd, currentPage, pageSize, totalPageNum) {
                if ('first' === cmd) {
                    currentPage = 1;
                } else if ('prev' === cmd) {
                    currentPage--;
                } else if ('next' === cmd) {
                    currentPage++;
                } else if ('last' === cmd) {
                    currentPage = totalPageNum;
                } else if ('change' === cmd) {
                    currentPage = 1;
                }
                $scope.userPageSearch(currentPage, pageSize);
            }
        };
        EdeyeAdmin.initDataTablePhone(userPageParam, {data: []});

        $scope.userPageSearch = function (currentPage, pageSize) {
            var postData = {order_id: $scope.order_id};
            postData.currentPage = (currentPage === undefined ? 1 : currentPage);
            postData.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(userPageParam.id) : pageSize);
            EdeyeAdmin.post({
                url: '/orderInfo/getOrderSetUserByOrderId',
                data: postData
            }, {
                SUCCESS: function (ret) {
                    if (ret.code === '500') {
                        // $scope.prefix = ret.prefix;
                        EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    }
                    EdeyeAdmin.setDataTableDataPhone(userPageParam, ret.data);
                    setTimeout(function(){
                    	$scope.miOpen('selectUserModal'); //打开里层
                    },1000);
                }
            });
        }
        
        // alert('3000');

        $scope.bind = {
            applicant_user: '',
            applicant_user_id: '',
            type: ''
        }

        // 弹出选择申领人的modal
        $scope.openSelectUserModal = function () {
            $scope.userPageSearch();
        };

        // 弹出选择申领人的modal,并关闭modal
        $scope.callBackSelectUserModal = function (data) {
            $scope.$apply(function () {
                $scope.bind.applicant_user = data.show_name;
                $scope.bind.applicant_user_id = data.id;
                $scope.bind.cardno = data.cardno;
            });
            $('#selectUserModal').modal('hide');
        }


        $scope.storeSetting = function (data) {
            $scope.order_id = data.id;
            $scope.bind = {};
            $scope.tbData = data;
            $scope.$apply();
            $scope.miOpen("storeSettingShow");
        }

        //提交同步申领单设置
        $scope.submitStoieSetting = function () {
            if (!$scope.bind.applicant_user_id) {
                EdeyeAdmin.closeMsg("请选择申请人", true, 1);
                return;
            }

            if (!$scope.tbData.type && !$scope.bind.type) {
                EdeyeAdmin.closeMsg("请选择申领单类型", true, 1);
                return;
            }

            $scope.bind.id = $scope.tbData.id;
            // alert(JSON.stringify($scope.bind));
            // return;

            EdeyeAdmin.post({
                url: '/orderInfo/orderApplicantUserSetting',
                data: {param: $scope.bind}
            }, {
                SUCCESS: function (ret) {
                    $scope.search();
                    EdeyeAdmin.closeMsg(ret.msg, true, 1);
                    // $scope.miClose('storeSettingShow'); //
                    $('#storeSettingShow').modal('hide');
                }
            });
        }

        //########################## 设置同步申领单申领人 END ##########################

        //正在申领的申领单取消
        $scope.orderInfoCancel = function () {
        	if($scope.orderCancelFlag !== 'CLICKABLE'){
        		return;
        	}
        	layer.confirm('是否确定取消?', {
        		btn: ['确认','取消'],
        		closeBtn: false
        	}, function(){
        		EdeyeAdmin.post({
                    url: '/reminder/orderInfoCancel',
                    data:{'warehouseId': $scope.warehouse_info_id }
                }, {
                    SUCCESS: function (ret) {
                        EdeyeAdmin.closeMsg(ret.msg, true, 1);
                        $scope.search();
                    }
                });
                layer.closeAll();
                $('#viewStoreModal').modal('hide');
            });
        }

    }]);


weiXinFilter.filter('materielSourceFilter', function () {
    return function (materielSource) {
        if (materielSource == 'IN') {
            return "账内";
        } else if (materielSource == 'OUT') {
            return "账外";
        } else {
            return materielSource;
        }
    }
});

weiXinFilter.filter('orderStatusFilter', function () {
    return function (input) {
        if (input === 'INIT') {
            return '未完成';
        } else if (input === 'UNBACK') {
            return '待归还';
        } else if (input === 'DOING') {
            return '处理中';
        } else if (input === 'DONE') {
            return '已完成';
        } else if (input === 'BINDED') {
            return '已绑定';
        } else if (input === 'BALANCED') {
            return '已冲销';
        } else if (input === 'CANCEL') {
            return '已取消';
        } else {
            return input;
        }
    }
});

weiXinFilter.filter('orderTypeFilter', function () {
    return function (input) {
        if (input === 'OUT') {
            return '出库';
        } else if (input === 'BALANCE') {
            return '冲销';
        } else if (input === 'BORROW') {
            return '借出';
        } else {
            return '待设置';
        }
    }
});